﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
using System.IO;
using TSL_Tools.SqlTools;

namespace ReportingEngine
{
    public partial class TSL_ReportingEngine
    {
        public static readonly string Sql_QUERY_SECTION_DELIMITER = @"--START CODE--";
        public static readonly string Sql_QUERY_DELIMITER = "GO\r\n";

        #region -- Messgae Strings -----------------------------------------------------------------------------------------------------
        /// <summary>
        /// Parameter 0: The name of the database that got updated
        /// Parameter 1: The string containing all of the updated made
        /// Parameter 2: The number of queries executed
        /// </summary>
        public static readonly string Msg_DATABASEUPDATEINFORMATION = @"Visual Studio Load Test database ({0}) was updated.
Added the following items:
{1}
Executed a total of {2} queries while processing. NOTE: 2 queries get executed for each stored procedure and one for each view.";
        #endregion

        #region -- SQL Queries ---------------------------------------------------------------------------------------------------------
        public static readonly string Sql_INSERT_DBCHANGELOG = @"
INSERT INTO TSL_DbChangeLogs (LoadTestRunId, ChangeTypeId, ChangeTime, LogComment) 
VALUES ({0}, {1}, GetDate(),'{2}') 
";

        public static readonly string Sql_GETRUNSFORDATAGRID = @"
SELECT LoadTestRunId AS 'Run #', LoadTestName, StartTime, RunDuration, [Description], FLAG_LoadTestParsingFailed AS [ParsingFailed] 
FROM TSL_View_LoadTestSummary WHERE Outcome != 'InProgress' ORDER BY LoadTestRunId DESC
";

        public static readonly string Sql_GETFILTEREDRUNLIST = @"
SELECT LoadTestRunId AS 'Run #', LoadTestName, StartTime, RunDuration, [Description], FLAG_LoadTestParsingFailed AS [ParsingFailed] 
FROM TSL_View_LoadTestSummary WHERE {0} {1} '{2}' AND Outcome != 'InProgress' ORDER BY LoadTestRunId DESC
";

        public static readonly string Sql_GETCORERUNLIST = @"
SELECT 
LoadTestRunId
,LoadTestName
,Description
,StartTime
,RunDuration
,RunSettingUsed
,ControllerName
,Outcome
,SampleInterval
,IsLocalRun
,FLAG_TestAborted
,FLAG_ContainsDetailedTimingInfo
,FLAG_ContainsPages
,FLAG_ContainsTransactions
,FLAG_LoadTestParsingFailed
,FLAG_ContainsStepLoadProfile
,LoadTest
,Comment
FROM TSL_View_LoadTestSummary ORDER BY LoadTestRunId DESC
";


        public static readonly string Sql_GETCORESCORECARDVALUESFORSINGLERUN = @"
SELECT
      [TotalTests]
      ,[PassedTests]
      ,[FailedTests]
      ,[AvgTT_All]
      ,[TestsSec_All]
      ,[TotalTrans]
      ,[AvgTrET_All]
      ,[AvgTrRT_All]
      ,[TransSec_All]
      ,[TotalPages]
      ,[PagesSec_All]
      ,[AvgPgT_All]
      ,[TotalRequests]
      ,[PassedRequests]
      ,[FailedRequests]
      ,[CachedRequests]
      ,[ReqSec_All]
      ,[AvgReqT_All]
      ,[AvgReqLen_All]
      ,[AvgTT_Pass]
      ,[TestsSec_Pass]
      ,[AvgTrET_Pass]
      ,[AvgTrRT_Pass]
      ,[TransSec_Pass]
      ,[PassedPages]
      ,[PagesSec_Pass]
      ,[AvgPgT_Pass]
FROM TSL_LoadTestCoreInfo WHERE LoadTestRunId = {0}
";

        

        public static readonly string Sql_GETAGENTLIST = @"
SELECT a.LoadTestRunId, a.AgentName FROM LoadTestRunAgent AS a INNER JOIN 
    TSL_View_LoadTestSummary AS b ON a.LoadTestRunId = b.LoadTestRunId
    WHERE b.FLAG_LoadTestParsingFailed != 1 ORDER BY a.LoadTestRunId ASC";




        public static readonly string Sql_GETPERFMONMACHINELIST = @"
SELECT DISTINCT MachineName FROM LoadTestPerformanceCounterCategory AS a
INNER JOIN LoadTestRunAgent AS b ON a.LoadTestRunId = b.LoadTestRunId
WHERE a.LoadTestRunId = {0} 
AND MachineName NOT IN 
	(SELECT AgentName FROM LoadTestRunAgent WHERE LoadTestRunId = {0}
	UNION SELECT ControllerName AS [AgentName] FROM LoadTestRun WHERE LoadTestRunId = {0})";

        
        
        public static readonly string Sql_GETTRANSANDPAGEMAXQTYCOUNT = @"
SELECT a.LoadTestRunId, COUNT(b.TransactionId) AS [TransactionCount],COUNT(c.PageId) AS [PageCount] FROM LoadTestRun AS a
LEFT JOIN LoadTestTransactionSummaryData AS b ON a.LoadTestRunId = b.LoadTestRunId
LEFT JOIN LoadTestPageSummaryData AS c ON a.LoadTestRunId = c.LoadTestRunId
WHERE a.Outcome != 'InProgress' 
GROUP BY a.LoadTestRunId ORDER BY a.LoadTestRunId ASC
";


        /// <summary>
        /// Parameter 0: a list of RunIds, seperated by commas
        /// Parameter 1: A filter string containing a partial or full name of machine(s) to use
        /// </summary>
        public static readonly string Sql_SCORECARDCPUQUERY = @"
SELECT 
	LoadTestRunId
	, MachineName
	, CAST(MIN(ComputedValue) AS Decimal(15,2)) AS [Min CPU] 
	, CAST(AVG(ComputedValue) AS Decimal(15,2)) AS [Avg CPU] 
	, CAST(MAX(ComputedValue) AS Decimal(15,2)) AS [Max CPU] 
FROM dbo.LoadTestComputedCounterSample
WHERE CategoryName = 'Processor' AND CounterName = '% Processor Time' AND InstanceName = '_Total'
AND MachineName LIKE '%{1}%'
AND LoadTestRunId IN ({0})
GROUP BY LoadTestRunId, MachineName
ORDER BY MachineName, LoadTestRunId ASC
";

        /// <summary>
        /// Parameter 0: The LoadTestRunId
        /// Parameter 1: The MachineName
        /// </summary>
        public static readonly string Sql_AVERAGECPUFORMACHINE = @"
SELECT CAST(CumulativeValue AS Decimal(15,2)) FROM LoadTestComputedCounterSummary
	WHERE LoadTestRunId = {0} AND CategoryName = 'Processor'
	AND CounterName = '% Processor Time' AND InstanceName = '_Total'
	AND MachineName = '{1}'
";

        /// <summary>
        /// Parameter 0: The LoadTestRunId
        /// </summary>
        public static readonly string Sql_GETLOADTESTBLOB = @"select LoadTest from LoadTestRun where LoadTestRunId = {0}";

        public static readonly string Sql_CHECKFORINSTALLEDREPORTING = @"SELECT name FROM sysobjects WHERE name = 'TSL_prc_Get_TSL_Reporting_Version' AND type = 'P'";

        /// <summary>
        /// Parameter 0: The LoadTestRunId
        /// </summary>
        public static readonly string Sql_GETPERFMONCOUNTSFORRUN = @"
SELECT 'Category Count' AS [Item], COUNT (*) AS [Qty] FROM LoadTestPerformanceCounterCategory WHERE LoadTestRunId = {0}
    UNION SELECT 'Counter Count', COUNT (*) FROM LoadTestPerformanceCounter WHERE LoadTestRunId = {0}
    UNION SELECT 'Instance Count', COUNT (*) FROM LoadTestPerformanceCounterInstance WHERE LoadTestRunId = {0}
    UNION SELECT 'Sample Count', COUNT (*) FROM LoadTestPerformanceCounterSample WHERE LoadTestRunId = {0}
";

        /// <summary>
        /// Pulls the InstanceId and the Instance's Display Name from the MTSL_View_PerfmonMachineInstanceNamesAndIds VIEW in the DB
        /// Parameter 0: LoadTestRunId
        /// Parameter 1: Category
        /// Parameter 2: Counter
        /// Parameter 3: InstanceName
        /// Parameter 4: Machine Name
        /// </summary>
        public static readonly string Sql_GETINSTANCEIDFROMINSTANCENAMEVIEW = @"SELECT InstanceId, InstanceName FROM MTSL_View_PerfmonInstanceNamesAndIds
            WHERE LoadTestRunId = {0} AND CategoryName = '{1}' AND CounterName = '{2}' AND Instance = '{3}' AND MachineName = '{4}'";

        /// <summary>
        /// Pulls the InstanceId and the Instance's Display Name from the MTSL_View_PerfmonMachineInstanceNamesAndIds VIEW in the DB
        /// Parameter 0: LoadTestRunId
        /// Parameter 1, 3, 5, 7: EITHER '=' or 'LIKE'
        /// Parameter 2: Category
        /// Parameter 4: Counter
        /// Parameter 6: Instance
        /// Parameter 8: Machine
        /// </summary>
        public static readonly string Sql_GETINSTANCEIDFROM_MULTI_INSTANCENAMEVIEW = @"SELECT * FROM MTSL_View_PerfmonInstanceNamesAndIds
            WHERE LoadTestRunId = {0} AND CategoryName {1} '{2}' AND CounterName {3} '{4}' AND Instance {5} '{6}' AND MachineName {7} '{8}'";

        /// <summary>
        /// Parameter 0: Chart Name
        /// Parameter 1: fixed scale value
        /// Parameter 2: LoadTestRunId
        /// Parameter 3: Category
        /// Parameter 4: Counter
        /// Parameter 5: InstanceName
        /// Parameter 6: Rig Machine Names List  e.g. '{agent1}', '{agent1}'
        /// Should return: ChartName, ChartType, LoadTestRunId, InstanceId, Category, Counter, Instance, Machine, SeriesName, fixedScale
        /// </summary>
        public static readonly string Sql_GETRIGMACHINECHARTOBJECT_INSTANCEIDS = @"SELECT '{0} - Rig' AS [ChartName], 'Rig' AS [ChartType], LoadTestRunId ,InstanceId
	        ,CategoryName AS [Category]	,CounterName AS [Counter] ,Instance, MachineName AS [Machine]
	        ,InstanceName AS [SeriesName], '{1}' AS [fixedScale] FROM MTSL_View_PerfmonInstanceNamesAndIds
            WHERE LoadTestRunId = {2} AND CategoryName = '{3}' AND CounterName = '{4}' AND Instance = '{5}' AND MachineName IN ({6})";

        /// <summary>
        /// Parameter 0: Chart Name
        /// Parameter 1: fixed scale value
        /// Parameter 2: LoadTestRunId
        /// Parameter 3: Category
        /// Parameter 4: Counter
        /// Parameter 5: InstanceName
        /// Parameter 6: Rig Machine Names List  e.g. '{agent1}', '{agent1}'
        /// Should return: ChartName, ChartType, LoadTestRunId, InstanceId, Category, Counter, Instance, Machine, SeriesName, fixedScale
        /// </summary>
        public static readonly string Sql_GETSUTMACHINECHARTOBJECT_INSTANCEIDS = @"
SELECT '{0} - SUT' AS [ChartName], 'Sut' AS [ChartType], LoadTestRunId ,InstanceId
    ,CategoryName AS [Category]	,CounterName AS [Counter] ,Instance, MachineName AS [Machine]
    ,InstanceName AS [SeriesName], '{1}' AS [fixedScale] FROM MTSL_View_PerfmonInstanceNamesAndIds
WHERE LoadTestRunId = {2} AND CategoryName = '{3}' AND CounterName = '{4}' AND Instance = '{5}' AND MachineName IN ({6})
ORDER BY [SeriesName] ASC
";

        /// <summary>
        /// Parameter 0: Chart Name
        /// Parameter 1: fixed scale value
        /// Parameter 2: LoadTestRunId
        /// Parameter 3: Category
        /// Parameter 4: Counter
        /// Parameter 5: InstanceName
        /// Should return: ChartName, ChartType, LoadTestRunId, InstanceId, Category, Counter, Instance, Machine, SeriesName, fixedScale
        /// </summary>
        public static readonly string Sql_GETKEYMETRICCHARTOBJECT_INSTANCEIDS = @"
SELECT '{0}' AS [ChartName], 'KeyMetric' AS [ChartType], LoadTestRunId ,InstanceId
    ,CategoryName AS [Category]	,CounterName AS [Counter] ,Instance, MachineName AS [Machine]
    ,InstanceName AS [SeriesName], '{1}' AS [fixedScale] FROM MTSL_View_PerfmonInstanceNamesAndIds
WHERE LoadTestRunId = {2} AND CategoryName = '{3}' AND CounterName = '{4}' AND Instance LIKE'{5}'
ORDER BY [SeriesName] ASC
";

        /// <summary>
        /// Parameter 0: Chart Name
        /// Parameter 1: fixed scale value
        /// Parameter 2: LoadTestRunId
        /// Parameter 3: Category
        /// Parameter 4: Counter
        /// Parameter 5: InstanceName
        /// Should return: ChartName, ChartType, LoadTestRunId, InstanceId, Category, Counter, Instance, Machine, SeriesName, fixedScale
        /// </summary>
        public static readonly string Sql_GETCOMBOMACHINECHARTOBJECT_INSTANCEIDS = @"
SELECT '{0}' AS [ChartName], 'Combo' AS [ChartType], LoadTestRunId ,InstanceId
    ,CategoryName AS [Category]	,CounterName AS [Counter] ,Instance, MachineName AS [Machine]
    ,InstanceName AS [SeriesName], '{1}' AS [fixedScale] FROM MTSL_View_PerfmonInstanceNamesAndIds
WHERE LoadTestRunId = {2} AND CategoryName = '{3}' AND CounterName = '{4}' AND Instance LIKE'{5}'
ORDER BY [SeriesName] ASC
";

        /// <summary>
        /// Parameter 0: Chart Name
        /// Parameter 1: fixed scale value
        /// Parameter 2: LoadTestRunId
        /// Parameter 3: Category
        /// Parameter 4: Counter
        /// Parameter 5: InstanceName
        /// Should return: ChartName, ChartType, LoadTestRunId, InstanceId, Category, Counter, Instance, Machine, SeriesName, fixedScale
        /// </summary>
        public static readonly string Sql_GETSCORECARDMACHINECHARTOBJECT_INSTANCEIDS = @"
SELECT '{0}' AS [ChartName], 'ScoreCard' AS [ChartType], LoadTestRunId ,InstanceId
	,CategoryName AS [Category]	,CounterName AS [Counter] ,Instance, MachineName AS [Machine]
	,InstanceName AS [SeriesName], '{1}' AS [fixedScale] FROM MTSL_View_PerfmonInstanceNamesAndIds
WHERE LoadTestRunId = {2} AND CategoryName = '{3}' AND CounterName = '{4}' AND Instance LIKE'{5}'
ORDER BY [SeriesName] ASC
";

        /// <summary>
        /// Parameter 0: The LoadTestRunId
        /// Parameter 1: The maximum quantity 
        /// </summary>
        public static readonly string Sql_GETTOPERRORSANDCOUNTS = @"
SELECT TOP {1} COUNT (RequestUri) AS Quantity ,TestCaseName ,RequestUri ,MessageText ,RequestId
    FROM LoadTestMessageView
WHERE SubType != 'LoadTestException' AND SubType NOT LIKE 'LoadTestCounter%'
AND LoadTestRunId = {0}
GROUP BY LoadTestRunId, TestCaseName, RequestUri, MessageText, RequestId
ORDER BY LoadTestRunId, Quantity DESC
";
        #endregion

        #region -- SQL Stored Procedures -----------------------------------------------------------------------------------------------
        #region -- QUERIES IN TSL_TestRunSummaryProcs.sql --
        public static readonly string Sql_SUMMARYTIMINGRESULTSFORREPORT = @"EXEC TSL_prc_SummaryTimingResultsForReport 
            @runId={0}, @IncludeTest={1}, @IncludeTransaction={2}, @IncludePage={3}";

        public static readonly string Sql_SUMMARYTIMINGRESULTSUSINGPERFMON = @"EXEC TSL_prc_SummaryTimingResultsUsingPerfmon 
            @runId={0}, @IncludeTest={1}, @IncludeTransaction={2}, @IncludePage={3}";

        public static readonly string Sql_SUMMARY_TESTRESULTS = @"EXEC TSL_prc_Summary_TestResults @runId = {0}, @NameFilter = {1},
            @StartOffset = {2}, @EndOffset = {3}, @IncludeFailedTests = {4}, @OrderByAverageTime = {5}, @IncludeWarmupCooldown = {6}, @NumberOfRows = {7}";

        public static readonly string Sql_SUMMARY_TRANSACTIONRESULTS = @"EXEC TSL_prc_Summary_TransactionResults @runId = {0}, @NameFilter = {1},
            @StartOffset = {2}, @EndOffset = {3}, @IncludeFailedTransactions = {4}, @OrderByAverageTime = {5}, @IncludeWarmupCooldown = {6}, @NumberOfRows = {7}";

        public static readonly string Sql_SUMMARY_PAGERESULTS = @"EXEC TSL_prc_Summary_PageResults @runId = {0}, @NameFilter = {1},
            @StartOffset = {2}, @EndOffset = {3}, @IncludeFailedPages = {4}, @OrderByAverageTime = {5}, @IncludeWarmupCooldown = {6}, @NumberOfRows = {7}";
        #endregion

        #region -- QUERIES IN TSL_Interval_Timing_Procs.sql --
        public static readonly string Sql_INTERVAL_TESTRESULTS = @"exec TSL_prc_Interval_TestResults @runId = {0}, @NameFilter = {1},
            @StartOffset = {2}, @EndOffset = {3}, @IncludeFailedTests = {4}, @OrderByAverageTime = {5}, @IncludeWarmupCooldown = {6}, @NumberOfRows = {7}";

        public static readonly string Sql_INTERVAL_TRANSACTIONRESULTS = @"exec TSL_prc_Interval_TransactionResults @runId = {0}, @NameFilter = {1},
            @StartOffset = {2}, @EndOffset = {3}, @IncludeFailedTransactions = {4}, @OrderByAverageTime = {5}, @IncludeWarmupCooldown = {6}, @NumberOfRows = {7}";

        public static readonly string Sql_TRANSACTIONRESULTS_GROUPEDBYNAME = @"exec TSL_prc_TransactionResults_GroupedByName @runId = {0}, @StartOffset = {1}, @EndOffset = {2}
, @NameFilter = {3},  @NumberOfRows = {4}";

        public static readonly string Sql_INTERVAL_PAGERESULTS = @"exec TSL_prc_Interval_PageResults @runId = {0}, @NameFilter = {1},
            @StartOffset = {2}, @EndOffset = {3}, @IncludeFailedPages = {4}, @OrderByAverageTime = {5}, @IncludeWarmupCooldown = {6}, @NumberOfRows = {7}";

        public static readonly string Sql_INTERVAL_PAGETHROUGHPUT = @"exec VSLT_prc_Interval_PageThroughput @runId = {0}, @NameFilter = {1},
            @StartOffset = {2}, @EndOffset = {3}, @NumberOfRows = {4}";

        public static readonly string Sql_PAGERESULTS_GROUPEDBYNAME = @"exec TSL_prc_PageResults_GroupedByName @runId = {0}, @StartOffset = {1}, @EndOffset = {2}
, @NameFilter = {3}, @NumberOfRows = {4}";

        public static readonly string Sql_USERLOADPROFILE = @"EXEC TSL_prc_UserLoadProfile @RunId = {0}";
        #endregion

        #region -- QUERIES IN TSL_Core_Procs.sql --
        public static readonly string Sql_GETDATABASEINFO = @"EXEC TSL_prc_GetDatabaseInfo @DatabaseName = {0}";

        public static readonly string Sql_GETTSLREPORTINGVERSION = @"EXEC TSL_prc_Get_TSL_Reporting_Version";

        public static readonly string Sql_BIGGESTTABLESBYROWS = @"EXEC TSL_prc_BiggestTablesByRows";

        public static readonly string Sql_DAILYSTATUSRUNLIST = @"exec TSL_prc_DailyStatusRunList @StartDate='{0}', @EndDate='{1}'";

        public static readonly string Sql_UPDATELOADTESTCOREINFO = @"EXEC TSL_prc_UpdateLoadTestCoreInfoTable";
        #endregion

        #region -- QUERIES IN TSL_PerfCounter_Procs.sql --
        public static readonly string Sql_PERFCOUNTEREXPORTTOCSV = @"EXEC TSL_prc_PerfCounterExportToCSV
            @runId={0}, @InstanceName={1}";

        //public static readonly string Sql_PERFMONCOUNTERCOUNTS = @"EXEC TSL_prc_PerfmonCounterCounts @runId={0}";

        /// <summary>
        /// Parameter 0: LoadTestRunId
        /// Parameter 1: InstanceId
        /// </summary>
        public static readonly string Sql_GETPERFMONCOUNTERSERIES = @"EXEC TSL_prc_PerfCounterValuesByInstanceId @RunId = {0}, @InstanceId = {1}";

        /// <summary>
        /// Parameter 0: LoadTestRunId
        /// Parameter 1: RequestUri
        /// </summary>
        public static readonly string Sql_GETPERFMON_PAGESAMPLES = @"EXEC TSL_prc_PerfCounterValuesFromPageSamples @RunId = {0}, @RequestUri = N'{1}', @RequestId = {2}";

        /// <summary>
        /// Parameter 0: LoadTestRunId
        /// Parameter 1: TransactionName
        /// </summary>
        public static readonly string Sql_GETPERFMON_TRANSACTIONSAMPLES = @"EXEC TSL_prc_PerfCounterValuesFromTransactionSamples @RunId = {0}, @TransactionName = N'{1}'";

        /// <summary>
        /// Parameter 0: LoadTestRunId
        /// Parameter 1: TestCaseName
        /// </summary>
        public static readonly string Sql_GETPERFMON_TESTCASESAMPLES = @"EXEC TSL_prc_PerfCounterValuesFromTestCaseSamples @RunId = {0}, @TestCaseName = N'{1}'";

        /// <summary>
        /// Parameter 0: LoadTestRunId
        /// Parameter 1: TestCaseName
        /// </summary>
        public static readonly string Sql_GETSTARTINGVALUESFORIMPORTINGPERFMON = @"EXEC TSL_prc_GetStartingValuesForImportingPerfmon @RunId = {0}";

        /// <summary>
        /// Parameter 0: LoadTestRunId
        /// </summary>
        public static readonly string Sql_UPDATEPERFMONIMPORT = "EXEC TSL_prc_UpdatePerfmonTablesFromImport {0}";
        #endregion
        #endregion

        #region -- SQL Code to clean up old procs and views ----------------------------------------------------------------------------
        public static string Sql_DELETEALLOLDSTOREDPROCEDURES = @"
                /*== Code to cleanup all old Procs =================================================================*/
	                --START CODE--
                declare @procName varchar(500) 
                declare cur cursor
                FOR SELECT name FROM sysobjects WHERE (name LIKE 'TSL_%' OR name LIKE 'MTSL_%' OR name LIKE 'VSLT_%') AND type = 'P'
                OPEN cur 
                fetch next from cur into @procName
                while @@fetch_status = 0
                begin
                exec('drop procedure ' + @procName)
                fetch next from cur into @procName 
                end
                close cur
                deallocate cur
";
        public static string Sql_DELETEALLOLDVIEWS = @"
                /*== Code to cleanup all old Views =================================================================*/
                --START CODE--
                declare @viewName varchar(500)
                declare cur cursor
                FOR SELECT name FROM sysobjects WHERE (name LIKE 'TSL_%' OR name LIKE 'MTSL_%' OR name LIKE 'VSLT_%') AND type = 'V'
                OPEN cur
                fetch next from cur into @viewName
                while @@fetch_status = 0
                begin
                exec('drop view ' + @viewName)
                fetch next from cur into @viewName 
                end
                close cur
                deallocate cur
";
        public static string Sql_DELETEALLOLDTABLES = @"
                /*== Code to cleanup all old Views =================================================================*/
                --START CODE--
				IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'TSL_LoadTestCoreInfo') AND type in (N'U'))
                BEGIN 
				DROP TABLE TSL_LoadTestCoreInfo
				END
				
                IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'TSL_ScoreCardMachineCPU') AND type in (N'U'))
                BEGIN 
				DROP TABLE TSL_ScoreCardMachineCPU
				END
				
                IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'TSL_ScoreCardMachineAvailableMB') AND type in (N'U'))
                BEGIN 
				DROP TABLE TSL_ScoreCardMachineAvailableMB
				END
				
                IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'TSL_StagingTableForPerfmonImports') AND type in (N'U'))
                BEGIN 
				DROP TABLE TSL_StagingTableForPerfmonImports
				END
				
                IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'TSL_LoadTestIntervals') AND type in (N'U'))
                BEGIN 
				DROP TABLE TSL_LoadTestIntervals
				END
				
                IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'TSL_DbChangeLogTypes') AND type in (N'U'))
                BEGIN 
				DROP TABLE TSL_DbChangeLogTypes
				END

				IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'VSLT_LoadTestCoreInfo') AND type in (N'U'))
                BEGIN 
				DROP TABLE VSLT_LoadTestCoreInfo
				END
				
                IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'VSLT_ScoreCardMachineCPU') AND type in (N'U'))
                BEGIN 
				DROP TABLE VSLT_ScoreCardMachineCPU
				END
				
                IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'VSLT_ScoreCardMachineAvailableMB') AND type in (N'U'))
                BEGIN 
				DROP TABLE VSLT_ScoreCardMachineAvailableMB
				END
				
                IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'VSLT_StagingTableForPerfmonImports') AND type in (N'U'))
                BEGIN 
				DROP TABLE VSLT_StagingTableForPerfmonImports
				END
				
                IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'VSLT_LoadTestIntervals') AND type in (N'U'))
                BEGIN 
				DROP TABLE VSLT_LoadTestIntervals
				END
				
                IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'VSLT_DbChangeLogTypes') AND type in (N'U'))
                BEGIN 
				DROP TABLE VSLT_DbChangeLogTypes
				END
";

        #endregion

    }
}
